#include "main_menu.h"

#include "game_screen.h"
#include <log.h>

bool MainMenu::create()
{
  _background = new Background();
  _background->setColour(Colour::BLACK);
  
  _start_button = new Button("START");
  _quit_button = new Button("QUIT");
  
  _column = new Column();
  _column->setSpacing(5);
  _column->add(_start_button);
  _column->add(_quit_button);
  
  GUI_setBackground(_background);
  GUI_setContent(_column);
  
  return true;
}

void MainMenu::destroy()
{
  delete _start_button;
  delete _quit_button;
  delete _column;
  delete _background;
}

void MainMenu::handleKeyDown(const GUIKeyDownEvent* event)
{
  if (event->getKey() == KEY_ESCAPE)
  {
    quit();
  }
}

void MainMenu::handleWidgetEvent(const GUIWidgetEvent* event)
{
  if (event->getEventType() == BUTTON_PRESSED)
  {
    if (event->getWidget() == _start_button)
    {
      GameScreen* game_screen = new GameScreen();
      
      GUI_runState(game_screen);
      
      delete game_screen;
    }
    else if (event->getWidget() == _quit_button)
    {  
      quit();
    }
  }
}
